﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MMVoiceComm
{
    public partial class CommandConfigForm : Form
    {
        private string commandName;
        private ConfigurationManager commandConfig;
        public CommandConfigForm(String configCommandName)
        {
            InitializeComponent();
            this.commandName = configCommandName;
            
        }

        private void CommandConfigForm_Load(object sender, EventArgs e)
        {
            commandConfig = new ConfigurationManager();
            this.Text = "Configuring Command - " + commandName;
            foreach(string commandVal in commandConfig.GetCommandValues(commandName))
            {
                this.commandListBox.Items.Add(commandVal);
            }
            if (this.commandListBox.Items.Count > 0) this.commandListBox.SelectedIndex = 0;
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            commandConfig.WriteCommands();
            this.Close();
        }

        private void removeCommandButton_Click(object sender, EventArgs e)
        {
            commandConfig.Commands[commandName].Remove(commandListBox.Items[commandListBox.SelectedIndex].ToString());
            commandListBox.Items.RemoveAt(commandListBox.SelectedIndex);
        }

        private void addCommandButton_Click(object sender, EventArgs e)
        {
            if (commandText.Text.Trim().Equals("")) {MessageBox.Show("Input Command Text Cannot Be Empty!");}
            else
            {
                commandListBox.Items.Add(commandText.Text);
                commandConfig.Commands[commandName].Add(commandText.Text);
                commandText.Text = "";
            }

        }

        private void CommandConfigForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            commandConfig.WriteCommands();
        }
    }
}
